package com.sskj.b70.v.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.sskj.b70.R;
import com.sskj.b70.quickmark.view.ViewfinderView;

import sskj.lee.appupdatelibrary.BaseUpdateDialogFragment;
import sskj.lee.appupdatelibrary.BaseVersion;
import sskj.lee.appupdatelibrary.NumberProgressBar;

/**
 * ProjectName：new_bfex
 * DESC: (类描述)
 * Created by 李岩 on 2018/7/6 0006
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class AppUpDateFragment extends BaseUpdateDialogFragment implements View.OnClickListener {

    private NumberProgressBar mUpdateProgressbar;
    private View mDialogCancel;
    private View mDialogConfirm;


    @Override
    public int getLayoutId() {
        return R.layout.fragment_app_update;
    }

    @Override
    protected void initView(View view, BaseVersion versionData) {
        mDialogCancel = view.findViewById(R.id.app_update_cancel);
        mDialogConfirm = view.findViewById(R.id.app_update_confirm);
        mDialogCancel.setOnClickListener(this);
        mDialogConfirm.setOnClickListener(this);
        TextView content = view.findViewById(R.id.app_update_content);
        mUpdateProgressbar = view.findViewById(R.id.update_dialog_progressbar);
        TextView title = view.findViewById(R.id.app_update_title);
        title.setText(versionData.getTitle());
        content.setText(versionData.getContent());
    }

    @Override
    protected void onDownLoadStart() {
        mDialogCancel.setEnabled(false);
        mDialogConfirm.setEnabled(false);
        mUpdateProgressbar.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onDownLoadUpdate(int progress) {
        mUpdateProgressbar.setProgress(progress);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.app_update_cancel:
                if (mVersionData.isMustUp()){
                    showMustUpDialog();
                }else {
                    dismiss();
                }
                break;
            case R.id.app_update_confirm:
                startDownload();
                break;
        }
    }
}
